1
超越单一提示:迈向复杂工作流的转变
AI010Lesson 4
00:00

“巨型提示”的终结

在早期大语言模型开发中,用户常常试图将每一条指令、约束和数据点都塞进一个巨大的单一提示中。尽管直觉上合理,但这种方法会导致过拟合,高昂的令牌成本,以及形成一个‘黑箱’,使得调试失败几乎变得不可能。

业界正转向提示链。这种模块化方法将大语言模型视为一系列专业化的工作者,而非一个过度工作的通才。

为何要使用提示链?

  • 可靠性:将复杂任务分解为可管理的子任务,能显著降低幻觉率。
  • 集成性:它允许你在工作流中途动态注入来自外部工具(如内部JSON数据库或API)的数据。
  • 成本效率:你只需为每个具体步骤发送必要上下文,从而节省令牌。
经验法则:任务分解
一个提示应只处理一项具体任务。如果你发现自己在一个提示指令中使用了超过三个“然后”语句,就该把它们拆分成独立调用。
pipeline.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute pipeline.
>
Knowledge Check
Why is "Dynamic Context Loading" (fetching data mid-workflow) preferred over putting all possible information into a single system prompt?
It makes the model run faster on local hardware.
It prevents model confusion and reduces token costs by only providing necessary data.
It allows the model to ignore the system instructions.
Challenge: Designing a Safe Support Bot
Apply prompt chaining principles to a real-world scenario.
You are building a tech support bot. A user asks for the manual of a "X-2000 Laptop."

Your task is to define the logical sequence of prompts needed to verify the product exists in your database and ensure the final output doesn't contain prohibited safety violations.
Step 1
What should the first two actions in your pipeline be immediately after receiving the user's message?
Solution:
1. Input Moderation: Check if the prompt contains malicious injection attempts. Evaluate as $ (N/Y) $.
2. Entity Extraction: Use a specialized prompt to extract the product name ("X-2000 Laptop") from the raw text.
Step 2
Once the entity is extracted, how do you generate the final safe response?
Solution:
1. Database Lookup: Query the internal DB for "X-2000 Laptop" manual data.
2. Response Generation: Pass the user query AND the retrieved DB data to the LLM to draft an answer.
3. Output Moderation: Run a final check on the generated text to ensure no safety policies were violated before sending it to the user.